package es.agroservicio.Agroservicio.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import es.agroservicio.Agroservicio.domain.Client;
import es.agroservicio.Agroservicio.repository.ClientsDAO;
import es.agroservicio.Agroservicio.service.ClientsManager;

@Controller
public class ClientsFormController extends MultiActionController {

	@Autowired
	private ClientsManager clientManager;

	@Autowired
	private ClientsDAO clientsDao;

	protected final Log logger = LogFactory.getLog(getClass());

	public String save(HttpServletRequest request, HttpServletResponse response,
			@Valid @ModelAttribute("newClient") Client newClient) {

		 clientsDao.saveOrUpdate(newClient);
		 return "redirect:/hello.html#ui-tabs-1";


	}

	public String delete(HttpServletRequest request,
			HttpServletResponse response,
			@Valid @ModelAttribute("newClient") Client clientToDelete)

	throws Exception, ServletException {
		clientsDao.deleteClient(clientToDelete);
		return "redirect:/hello.html#ui-tabs-1";

	}

}
